{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "dates = pd.date_range('20180615', periods=6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "dates = pd.date_range('20180615', periods=6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-06-15', '2018-06-16', '2018-06-17', '2018-06-18',\n",
       "               '2018-06-19', '2018-06-20'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = pd.DataFrame(np.random.randn(6,4),index=dates, columns=list('ABCD'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>0.422154</td>\n",
       "      <td>0.826989</td>\n",
       "      <td>-0.030305</td>\n",
       "      <td>0.438730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.123047</td>\n",
       "      <td>0.495640</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-0.203043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>-0.036979</td>\n",
       "      <td>-0.716290</td>\n",
       "      <td>-0.081198</td>\n",
       "      <td>-1.281483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-20</th>\n",
       "      <td>1.610591</td>\n",
       "      <td>-0.644550</td>\n",
       "      <td>-0.706517</td>\n",
       "      <td>0.049857</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-15  0.422154  0.826989 -0.030305  0.438730\n",
       "2018-06-16 -0.123047  0.495640 -1.434860 -0.203043\n",
       "2018-06-17 -0.853553 -3.275426 -1.012849  0.459301\n",
       "2018-06-18  0.826947  2.041252  1.462267 -0.408260\n",
       "2018-06-19 -0.036979 -0.716290 -0.081198 -1.281483\n",
       "2018-06-20  1.610591 -0.644550 -0.706517  0.049857"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6, 4)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.42215379,  0.82698893, -0.0303049 ,  0.43873017],\n",
       "       [-0.12304726,  0.49564008, -1.43486049, -0.20304325],\n",
       "       [-0.85355295, -3.27542619, -1.01284912,  0.45930114],\n",
       "       [ 0.82694658,  2.04125163,  1.46226654, -0.40826021],\n",
       "       [-0.03697895, -0.71629013, -0.08119785, -1.28148336],\n",
       "       [ 1.61059056, -0.64454993, -0.70651711,  0.04985731]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>0.422154</td>\n",
       "      <td>0.826989</td>\n",
       "      <td>-0.030305</td>\n",
       "      <td>0.438730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.123047</td>\n",
       "      <td>0.495640</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-0.203043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>-0.036979</td>\n",
       "      <td>-0.716290</td>\n",
       "      <td>-0.081198</td>\n",
       "      <td>-1.281483</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-15  0.422154  0.826989 -0.030305  0.438730\n",
       "2018-06-16 -0.123047  0.495640 -1.434860 -0.203043\n",
       "2018-06-17 -0.853553 -3.275426 -1.012849  0.459301\n",
       "2018-06-18  0.826947  2.041252  1.462267 -0.408260\n",
       "2018-06-19 -0.036979 -0.716290 -0.081198 -1.281483"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>0.422154</td>\n",
       "      <td>0.826989</td>\n",
       "      <td>-0.030305</td>\n",
       "      <td>0.438730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.123047</td>\n",
       "      <td>0.495640</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-0.203043</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-15  0.422154  0.826989 -0.030305  0.438730\n",
       "2018-06-16 -0.123047  0.495640 -1.434860 -0.203043"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.123047</td>\n",
       "      <td>0.495640</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-0.203043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>-0.036979</td>\n",
       "      <td>-0.716290</td>\n",
       "      <td>-0.081198</td>\n",
       "      <td>-1.281483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-20</th>\n",
       "      <td>1.610591</td>\n",
       "      <td>-0.644550</td>\n",
       "      <td>-0.706517</td>\n",
       "      <td>0.049857</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-16 -0.123047  0.495640 -1.434860 -0.203043\n",
       "2018-06-17 -0.853553 -3.275426 -1.012849  0.459301\n",
       "2018-06-18  0.826947  2.041252  1.462267 -0.408260\n",
       "2018-06-19 -0.036979 -0.716290 -0.081198 -1.281483\n",
       "2018-06-20  1.610591 -0.644550 -0.706517  0.049857"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>6.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>6.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.307685</td>\n",
       "      <td>-0.212064</td>\n",
       "      <td>-0.300577</td>\n",
       "      <td>-0.157483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.852420</td>\n",
       "      <td>1.815675</td>\n",
       "      <td>1.018578</td>\n",
       "      <td>0.649188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-1.281483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.101530</td>\n",
       "      <td>-0.698355</td>\n",
       "      <td>-0.936266</td>\n",
       "      <td>-0.356956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.192587</td>\n",
       "      <td>-0.074455</td>\n",
       "      <td>-0.393857</td>\n",
       "      <td>-0.076593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.725748</td>\n",
       "      <td>0.744152</td>\n",
       "      <td>-0.043028</td>\n",
       "      <td>0.341512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.610591</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              A         B         C         D\n",
       "count  6.000000  6.000000  6.000000  6.000000\n",
       "mean   0.307685 -0.212064 -0.300577 -0.157483\n",
       "std    0.852420  1.815675  1.018578  0.649188\n",
       "min   -0.853553 -3.275426 -1.434860 -1.281483\n",
       "25%   -0.101530 -0.698355 -0.936266 -0.356956\n",
       "50%    0.192587 -0.074455 -0.393857 -0.076593\n",
       "75%    0.725748  0.744152 -0.043028  0.341512\n",
       "max    1.610591  2.041252  1.462267  0.459301"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2018-06-15 00:00:00</th>\n",
       "      <th>2018-06-16 00:00:00</th>\n",
       "      <th>2018-06-17 00:00:00</th>\n",
       "      <th>2018-06-18 00:00:00</th>\n",
       "      <th>2018-06-19 00:00:00</th>\n",
       "      <th>2018-06-20 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>0.422154</td>\n",
       "      <td>-0.123047</td>\n",
       "      <td>-0.853553</td>\n",
       "      <td>0.826947</td>\n",
       "      <td>-0.036979</td>\n",
       "      <td>1.610591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0.826989</td>\n",
       "      <td>0.495640</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>-0.716290</td>\n",
       "      <td>-0.644550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-0.030305</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.081198</td>\n",
       "      <td>-0.706517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0.438730</td>\n",
       "      <td>-0.203043</td>\n",
       "      <td>0.459301</td>\n",
       "      <td>-0.408260</td>\n",
       "      <td>-1.281483</td>\n",
       "      <td>0.049857</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   2018-06-15  2018-06-16  2018-06-17  2018-06-18  2018-06-19  2018-06-20\n",
       "A    0.422154   -0.123047   -0.853553    0.826947   -0.036979    1.610591\n",
       "B    0.826989    0.495640   -3.275426    2.041252   -0.716290   -0.644550\n",
       "C   -0.030305   -1.434860   -1.012849    1.462267   -0.081198   -0.706517\n",
       "D    0.438730   -0.203043    0.459301   -0.408260   -1.281483    0.049857"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-20</th>\n",
       "      <td>1.610591</td>\n",
       "      <td>-0.644550</td>\n",
       "      <td>-0.706517</td>\n",
       "      <td>0.049857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>-0.036979</td>\n",
       "      <td>-0.716290</td>\n",
       "      <td>-0.081198</td>\n",
       "      <td>-1.281483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.123047</td>\n",
       "      <td>0.495640</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-0.203043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>0.422154</td>\n",
       "      <td>0.826989</td>\n",
       "      <td>-0.030305</td>\n",
       "      <td>0.438730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-20  1.610591 -0.644550 -0.706517  0.049857\n",
       "2018-06-19 -0.036979 -0.716290 -0.081198 -1.281483\n",
       "2018-06-18  0.826947  2.041252  1.462267 -0.408260\n",
       "2018-06-17 -0.853553 -3.275426 -1.012849  0.459301\n",
       "2018-06-16 -0.123047  0.495640 -1.434860 -0.203043\n",
       "2018-06-15  0.422154  0.826989 -0.030305  0.438730"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.sort_index(axis=0,ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-17 -0.853553 -3.275426 -1.012849  0.459301\n",
       "2018-06-18  0.826947  2.041252  1.462267 -0.408260"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-17 -0.853553 -3.275426 -1.012849  0.459301\n",
       "2018-06-18  0.826947  2.041252  1.462267 -0.408260"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A   -0.123047\n",
       "B    0.495640\n",
       "C   -1.434860\n",
       "D   -0.203043\n",
       "Name: 2018-06-16 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.49564007817798433"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iat[1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24.1 µs ± 3.3 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit data.iat[1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data.iat[1,1]=100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>0.422154</td>\n",
       "      <td>0.826989</td>\n",
       "      <td>-0.030305</td>\n",
       "      <td>0.438730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.123047</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>-1.434860</td>\n",
       "      <td>-0.203043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.853553</td>\n",
       "      <td>-3.275426</td>\n",
       "      <td>-1.012849</td>\n",
       "      <td>0.459301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.826947</td>\n",
       "      <td>2.041252</td>\n",
       "      <td>1.462267</td>\n",
       "      <td>-0.408260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>-0.036979</td>\n",
       "      <td>-0.716290</td>\n",
       "      <td>-0.081198</td>\n",
       "      <td>-1.281483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-20</th>\n",
       "      <td>1.610591</td>\n",
       "      <td>-0.644550</td>\n",
       "      <td>-0.706517</td>\n",
       "      <td>0.049857</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A           B         C         D\n",
       "2018-06-15  0.422154    0.826989 -0.030305  0.438730\n",
       "2018-06-16 -0.123047  100.000000 -1.434860 -0.203043\n",
       "2018-06-17 -0.853553   -3.275426 -1.012849  0.459301\n",
       "2018-06-18  0.826947    2.041252  1.462267 -0.408260\n",
       "2018-06-19 -0.036979   -0.716290 -0.081198 -1.281483\n",
       "2018-06-20  1.610591   -0.644550 -0.706517  0.049857"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = pd.DataFrame(np.random.randn(6,4), index=dates,columns=list('ABCD'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>1.463250</td>\n",
       "      <td>0.500309</td>\n",
       "      <td>1.132488</td>\n",
       "      <td>0.219369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.302025</td>\n",
       "      <td>-0.368025</td>\n",
       "      <td>1.520669</td>\n",
       "      <td>-0.551189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.559434</td>\n",
       "      <td>-0.376443</td>\n",
       "      <td>-0.553823</td>\n",
       "      <td>0.462558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.316676</td>\n",
       "      <td>-1.169389</td>\n",
       "      <td>1.278982</td>\n",
       "      <td>1.223589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>0.630835</td>\n",
       "      <td>0.504424</td>\n",
       "      <td>-0.423277</td>\n",
       "      <td>-1.071047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-20</th>\n",
       "      <td>1.218554</td>\n",
       "      <td>0.278207</td>\n",
       "      <td>0.023285</td>\n",
       "      <td>-0.295998</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-15  1.463250  0.500309  1.132488  0.219369\n",
       "2018-06-16 -0.302025 -0.368025  1.520669 -0.551189\n",
       "2018-06-17 -0.559434 -0.376443 -0.553823  0.462558\n",
       "2018-06-18  0.316676 -1.169389  1.278982  1.223589\n",
       "2018-06-19  0.630835  0.504424 -0.423277 -1.071047\n",
       "2018-06-20  1.218554  0.278207  0.023285 -0.295998"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>1.463250</td>\n",
       "      <td>0.500309</td>\n",
       "      <td>1.132488</td>\n",
       "      <td>0.219369</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.302025</td>\n",
       "      <td>-0.368025</td>\n",
       "      <td>1.520669</td>\n",
       "      <td>-0.551189</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.559434</td>\n",
       "      <td>-0.376443</td>\n",
       "      <td>-0.553823</td>\n",
       "      <td>0.462558</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.316676</td>\n",
       "      <td>-1.169389</td>\n",
       "      <td>1.278982</td>\n",
       "      <td>1.223589</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D   E\n",
       "2018-06-15  1.463250  0.500309  1.132488  0.219369 NaN\n",
       "2018-06-16 -0.302025 -0.368025  1.520669 -0.551189 NaN\n",
       "2018-06-17 -0.559434 -0.376443 -0.553823  0.462558 NaN\n",
       "2018-06-18  0.316676 -1.169389  1.278982  1.223589 NaN"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>1.463250</td>\n",
       "      <td>0.500309</td>\n",
       "      <td>1.132488</td>\n",
       "      <td>0.219369</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.302025</td>\n",
       "      <td>-0.368025</td>\n",
       "      <td>1.520669</td>\n",
       "      <td>-0.551189</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.559434</td>\n",
       "      <td>-0.376443</td>\n",
       "      <td>-0.553823</td>\n",
       "      <td>0.462558</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.316676</td>\n",
       "      <td>-1.169389</td>\n",
       "      <td>1.278982</td>\n",
       "      <td>1.223589</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D    E\n",
       "2018-06-15  1.463250  0.500309  1.132488  0.219369  NaN\n",
       "2018-06-16 -0.302025 -0.368025  1.520669 -0.551189  2.0\n",
       "2018-06-17 -0.559434 -0.376443 -0.553823  0.462558  2.0\n",
       "2018-06-18  0.316676 -1.169389  1.278982  1.223589  NaN"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.loc[dates[1:3],'E']=2\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.302025</td>\n",
       "      <td>-0.368025</td>\n",
       "      <td>1.520669</td>\n",
       "      <td>-0.551189</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.559434</td>\n",
       "      <td>-0.376443</td>\n",
       "      <td>-0.553823</td>\n",
       "      <td>0.462558</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D    E\n",
       "2018-06-16 -0.302025 -0.368025  1.520669 -0.551189  2.0\n",
       "2018-06-17 -0.559434 -0.376443 -0.553823  0.462558  2.0"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>1.463250</td>\n",
       "      <td>0.500309</td>\n",
       "      <td>1.132488</td>\n",
       "      <td>0.219369</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.302025</td>\n",
       "      <td>-0.368025</td>\n",
       "      <td>1.520669</td>\n",
       "      <td>-0.551189</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.559434</td>\n",
       "      <td>-0.376443</td>\n",
       "      <td>-0.553823</td>\n",
       "      <td>0.462558</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.316676</td>\n",
       "      <td>-1.169389</td>\n",
       "      <td>1.278982</td>\n",
       "      <td>1.223589</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D    E\n",
       "2018-06-15  1.463250  0.500309  1.132488  0.219369  5.0\n",
       "2018-06-16 -0.302025 -0.368025  1.520669 -0.551189  2.0\n",
       "2018-06-17 -0.559434 -0.376443 -0.553823  0.462558  2.0\n",
       "2018-06-18  0.316676 -1.169389  1.278982  1.223589  5.0"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.fillna(value=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    False\n",
       "B    False\n",
       "C    False\n",
       "D    False\n",
       "E     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.isnull(df1).any()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    0.229617\n",
       "B   -0.353387\n",
       "C    0.844579\n",
       "D    0.338582\n",
       "E    2.000000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2018-06-15    0.828854\n",
       "2018-06-16    0.459886\n",
       "2018-06-17    0.194572\n",
       "2018-06-18    0.412464\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.mean(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    2.022685\n",
       "B    1.673814\n",
       "C    2.074493\n",
       "D    2.294636\n",
       "dtype: float64"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.apply(lambda x : x.max()-x.min())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-06-15</th>\n",
       "      <td>1.463250</td>\n",
       "      <td>0.500309</td>\n",
       "      <td>1.132488</td>\n",
       "      <td>0.219369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-16</th>\n",
       "      <td>-0.302025</td>\n",
       "      <td>-0.368025</td>\n",
       "      <td>1.520669</td>\n",
       "      <td>-0.551189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-17</th>\n",
       "      <td>-0.559434</td>\n",
       "      <td>-0.376443</td>\n",
       "      <td>-0.553823</td>\n",
       "      <td>0.462558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-18</th>\n",
       "      <td>0.316676</td>\n",
       "      <td>-1.169389</td>\n",
       "      <td>1.278982</td>\n",
       "      <td>1.223589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-19</th>\n",
       "      <td>0.630835</td>\n",
       "      <td>0.504424</td>\n",
       "      <td>-0.423277</td>\n",
       "      <td>-1.071047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-20</th>\n",
       "      <td>1.218554</td>\n",
       "      <td>0.278207</td>\n",
       "      <td>0.023285</td>\n",
       "      <td>-0.295998</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2018-06-15  1.463250  0.500309  1.132488  0.219369\n",
       "2018-06-16 -0.302025 -0.368025  1.520669 -0.551189\n",
       "2018-06-17 -0.559434 -0.376443 -0.553823  0.462558\n",
       "2018-06-18  0.316676 -1.169389  1.278982  1.223589\n",
       "2018-06-19  0.630835  0.504424 -0.423277 -1.071047\n",
       "2018-06-20  1.218554  0.278207  0.023285 -0.295998"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.concat([df.iloc[:2],df.iloc[2:]])\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('bar', 'one'),\n",
       " ('bar', 'two'),\n",
       " ('baz', 'one'),\n",
       " ('baz', 'two'),\n",
       " ('foo', 'one'),\n",
       " ('foo', 'two'),\n",
       " ('qux', 'two'),\n",
       " ('qux', 'one')]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuples = list(zip(*[['bar', 'bar', 'baz','baz',\n",
    "                    'foo', 'foo', 'qux', 'qux'],\n",
    "                    ['one', 'two', 'one', 'two',\n",
    "                    'one', 'two', 'two', 'one']]))\n",
    "tuples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "object of type 'type' has no len()",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-74-0a021cf6d1dd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mindex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mMultiIndex\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfrom_tuples\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtuple\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnames\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'first'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'second'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\multi.py\u001b[0m in \u001b[0;36mfrom_tuples\u001b[1;34m(cls, tuples, sortorder, names)\u001b[0m\n\u001b[0;32m   1134\u001b[0m                                   \u001b[0mof\u001b[0m \u001b[0miterables\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1135\u001b[0m         \"\"\"\n\u001b[1;32m-> 1136\u001b[1;33m         \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtuples\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1137\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mnames\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1138\u001b[0m                 \u001b[0mmsg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'Cannot infer number of levels from empty list'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: object of type 'type' has no len()"
     ]
    }
   ],
   "source": [
    "index = pd.MultiIndex.from_tuples(tuple, names=['first', 'second'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
